import { useFetch } from "@/http/useFetch";

export const fetchRole = async function (data?: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "get"
    },
    url: "/role/list"
  });
};
export const fetchRoleAdd = async function (data?: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: "/role/add"
  });
};
export const fetchRoleSearch = async function (data?: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "get"
    },
    url: "/role/search"
  });
};

export const fetchRoleFunction = async function (data?: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "get"
    },
    url: "/role/functions"
  });
};

export const fetchRoleUpdate = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: "/role/update"
  });
};
export const fetchRoleRemove = async function (data: any): Promise<any> {
  return await useFetch({
    data,
    config: {
      method: "post"
    },
    url: "/role/remove"
  });
};
//kate

export const fetchDeepseek = async function (data: string, callback:Function): Promise<any> {
  const eventSource = new EventSource("/deepseek-api/deepseek/get?question=" + data);

  eventSource.onmessage = function(event) {
    callback && callback(typeof event.data === 'string'? event.data : new TextDecoder('utf-8').decode(event.data));
    // 在这里处理你的数据
  };

  eventSource.onerror = function(error) {
    eventSource.close();
    console.error('Error occurred:', error);
    // 处理错误
  };

};